package com.acwing.partition2;

import java.io.*;

/**
 * @author `RKC`
 * @date 2022/1/4 14:50
 */
public class AC180排书idaStar {

    private static final int N = 20;
    private static int n = 0;
    private static int[] nums = new int[N];

    private static final BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    private static final BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(System.out));

    public static void main(String[] args) throws IOException {
        int k = Integer.parseInt(reader.readLine());
        while (k-- > 0) {
            n = Integer.parseInt(reader.readLine());
            String[] s = reader.readLine().split("\\s+");
            for (int i = 0; i < n; i++) nums[i] = Integer.parseInt(s[i]);
            int maxDepth = 0;
            while (maxDepth < 5 && !idaStar(0, maxDepth)) maxDepth++;
            if (maxDepth >= 5) writer.write("5 or more\n");
            else writer.write(maxDepth + "\n");
        }
        writer.flush();
    }

    private static boolean idaStar(int depth, int maxDepth) {
        //如果当前的层数加上估价值都无法到达目标状态，就直接返回
        if (depth + eval() > maxDepth) return false;
        if (eval() == 0) return true;
        int[] numsTemp = new int[n];
        for (int length = 1; length <= n; length++) {
            for (int i = 0; i + length - 1 < n; i++) {
                int j = i + length - 1;
                //尝试把[i,j]区间这一段放在j之后的每一个空里面
                for (int k = j + 1; k < n; k++) {
                    System.arraycopy(nums, 0, numsTemp, 0, n);
                    int y = i;
                    //把(j,k]这一段移前去，然后把[i,j]一段放在移动后的k的后面
                    for (int x = j + 1; x <= k; x++, y++) nums[y] = numsTemp[x];
                    for (int x = i; x <= j; x++, y++) nums[y] = numsTemp[x];
                    if (idaStar(depth + 1, maxDepth)) return true;
                    //恢复现场
                    System.arraycopy(numsTemp, 0, nums, 0, n);
                }
            }
        }
        return false;
    }

    private static int eval() {
        //得到当前状态的估价值
        int res = 0;
        for (int i = 0; i + 1 < n; i++) {
            if (nums[i + 1] != nums[i] + 1) res++;
        }
        return (res + 2) / 3;
    }
}
